<template>
	<layout>
		<el-tree
			:data="data"
			show-checkbox
			node-key="id"
			@check="check"
			:default-checked-keys="permissions"
		>
		</el-tree>
	</layout>
</template>

<script>
export default {
	data() {
		return {
			data: [],
			permissions: [],
		}
	},
	created() {
		this.$http.get(`/permission/select`).then((res) => {
			if (res.errcode == 0) {
				this.data = res.data
			}
		})

		this.$http.get(`/user/info?id=${this.$route.params.id}`).then((res) => {
			if (res.errcode == 0) {
				this.permissions = res.data.permissionIds
			}
		})
	},

	methods: {
		check( checkedNode, checkedKeys ) {
			this.$http.post(`/permission/batch`,{
                    user_id:this.$route.params.id,
                    ids:checkedKeys.checkedKeys
                })
				.then((res) => {
					if (res.errcode == 0) {
						
					}
				})
		},
	},
}
</script>

<style></style>
